<!-- Modal -->
<div class="modal-dialog wide" style="width: 550px;">
<div class="modal-content">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="myModalLabel">
            <#if xcJjb??>
                <#if xcJjb.id??>
                    编辑
                <#else>
                    新增
                </#if>
            </#if>
        </h4>
    </div>
    <div class="modal-body">
        <div id="errorMessage"><#include "../../message.ftl" /></div>
        <form class="form-horizontal" role="form" id="xcJjbForm" method="post" action="${absoluteContextPath}/xc/xcJjb/save">
            <#if xcJjb??>
                <#if xcJjb.id??>
                    <input type="hidden" name="id" value="${xcJjb.id}"/>
                <#else>
                    <input type="hidden" name="id" value=""/>
                </#if>
            </#if>
            <div class="row">

            <div class="form-group col-md-6">
                <label class="col-sm-4 control-label">录入日期</label>
                <div class="col-sm-8">
                    <input name="entryDate" value="${(xcJjb.entryDate?string("yyyy-MM-dd"))!''}" type="text" class="form-control" onblur=funChoose(this.value) />
                </div>
            </div>
            <div class="form-group col-md-6">
                <label class="col-sm-4 control-label">个人领取</label>
                <div class="col-sm-8">
                    <input name="grBgrq" value="${xcJjb.grBgrq!''}" type="text" class="form-control"/>
                </div>
            </div>
            <div class="form-group col-md-6">
                <label class="col-sm-4 control-label">AK领取</label>
                <div class="col-sm-8">
                    <input name="akBgrq" value="${xcJjb.akBgrq!''}" type="text" class="form-control"/>
                </div>
            </div>
                <div class="form-group col-md-6">
                    <label class="col-sm-4 control-label">TTM</label>
                    <div class="col-sm-8">
                        <input name="ttm" value="${xcJjb.ttm!''}" type="text" class="form-control"/>
                    </div>
                </div>
            <div class="form-group col-md-6">
                <label class="col-sm-4 control-label">A健康礼品</label>
                <div class="col-sm-8">
                    <input name="ALp" value="${xcJjb.ALp!''}" type="text" class="form-control"/>
                </div>
            </div>
            <div class="form-group col-md-6">
                <label class="col-sm-4 control-label">B健康礼品</label>
                <div class="col-sm-8">
                    <input name="BLp" value="${xcJjb.BLp!''}" type="text" class="form-control"/>
                </div>
            </div>
            <div class="form-group col-md-6">
                <label class="col-sm-4 control-label">C健康礼品</label>
                <div class="col-sm-8">
                    <input name="CLp" value="${xcJjb.CLp!''}" type="text" class="form-control"/>
                </div>
            </div>
            <div class="form-group col-md-6">
                <label class="col-sm-4 control-label">D健康礼品</label>
                <div class="col-sm-8">
                    <input name="DLp" value="${xcJjb.DLp!''}" type="text" class="form-control"/>
                </div>
            </div>

            </div>
                <div class="row">
                    <div class="tile-header">
                        <h1>
                            <button type="button" class="btn btn-green" onclick="doAddjjbmx();"><i
                                    class="fa fa-plus"></i><span class="margin-left-5">新增</span></button>
                        </h1>
                    </div>
                    <div class="tile-body nopadding">
                        <div class="table-responsive" id="tableContent">
                            <table class="table table-datatable table-gray" id="tab">
                                <thead>
                                <tr>
                                    <th style="display:none;">ID</th>
                                    <th>用户姓名</th>
                                    <th>健康宣教讲解</th>
                                    <th>健康宣教引荐</th>
                                    <th>体检报告讲解</th>
                                    <th>体检报告跟进</th>
                                    <th style="width: 10%">操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                <#if jjbmxList??>
                                    <#list jjbmxList as jjbmx>
                                    <tr id="${jjbmx.id!''}" align="center">

                                        <td  style="display:none;" ><input  name="ids" value="${jjbmx.id!''}"
                                                                         type="text" class="form-control"/></td>
                                        <td><input name="userName" value="${jjbmx.userName!''}" type="text"
                                                   class="form-control"/></td>
                                        <td><input name="jkxjYj" value="${jjbmx.jkxjYj!''}" type="text"
                                                   class="form-control"/></td>
                                        <td><input name="jkxjJj" value="${jjbmx.jkxjJj!''}" type="text"
                                                   class="form-control"/></td>
                                        <td><input name="tjJj" value="${jjbmx.tjJj!''}" type="text"
                                                   class="form-control"/></td>
                                        <td><input name="tjGj" value="${jjbmx.tjGj!''}" type="text"
                                                   class="form-control"/></td>
                                        <#if (jjbmx.id>0)>
                                        <td><a class="btn btn-orange btn-radio  nopadding"
                                               onclick="deleteEditjjbmx(${jjbmx.id!''});" title="删除"> <i
                                                class="fa fa-trash-o"></i> </a></td>
                                        <#else >
                                            <td><a class="btn btn-orange btn-radio  nopadding"
                                                   onclick="deleteAddRemove(${jjbmx.id!''});" title="删除"> <i
                                                    class="fa fa-trash-o"></i> </a></td>
                                        </#if>
                                    </tr>

                                    </#list>
                                </#if>

                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
        </form>
    </div>
    <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</button>
        <button type="button" class="btn btn-primary" onclick="save();">保存</button>
    </div>
</div>
</div>
<script>
    function save() {
        $("#" + "xcJjbForm").ajaxSubmit({
            success:function(data) {
                data = JSON.parse(data);
                if (data.returnCode == 1) {
                    $('#myModal').modal("hide");
                    $.showMessage({parentId:"showMessage",message:"信息保存成功！",type:"success"});
                    refreshTable();
                } else {
                    $.showMessage({parentId:"errorMessage",message:"<strong>错误信息</strong>：" + data.returnMsg,type:"error"});
                }
            }
        });
    }
    var rowCount = 0;
    function doAddjjbmx() {

        rowCount++;
        $("#tab").append("<tr id='option" + rowCount + "' align='center'>"
                + "<td style='display:none;'><input name='ids' value='' type='text' class='form-control' /></td>"
                + "<td><input name='userName' value='' type='text' class='form-control' /></td>"
                + "<td><input name='jkxjYj' value='' type='text'  class='form-control'/></td>"
                + "<td><input name='jkxjJj' value='' type='text'  class='form-control'/></td>"
                + "<td><input name='tjJj' value='' type='text'  class='form-control'/></td>"
                + "<td><input name='tjGj' value='' type='text'  class='form-control'/></td>"
                + "<td><a class='btn btn-orange btn-radio  nopadding' onclick='deleteAddjjbmx(" + rowCount + ");' title='删除'> <i class='fa fa-trash-o'></i> </a></td>"
                + "</tr>");
    }

    function deleteEditjjbmx(id) {
        if (id != undefined) {
            $.confirm({
                confirm: function () {
                    $("#confirmModal").modal("hide");
                    $.post("${absoluteContextPath}/xc/xcJjbmx/delete", {
                        'id': id
                    }, function (data) {
                        data = JSON.parse(data);
                        if (data.returnCode == 1) {
                            $.showMessage({parentId: "errorMessage", message: "问题答案数据删除成功！", type: "success"});
                            $("#" + id + "").remove();
                        } else {
                            $.showMessage({parentId: "errorMessage", message: "问题答案数据删除异常！", type: "error"});
                        }
                    });
                }
            });
        }
    }

    function deleteAddjjbmx(rowCount) {
        $("#option" + rowCount + "").remove();
    }
    function deleteAddRemove(id) {
        $("#" + id + "").remove();
    }

    $(function () {
        $("input[name=entryDate]").focus(function () {
            WdatePicker({dateFmt: 'yyyy-MM-dd'});
        })
              $("div[class='tooltip fade top in']").hide();
    });

    function funChoose(entryDate) {

        var data = {};
        var url = '${absoluteContextPath}/xc/xcJjb';
        if(entryDate!=''){
          data.entryDate = entryDate;
          url = url + "/goChoose";
        }
        $.ajax({
            url: url,
            type: 'post',
            data: data,
            success: function (data) {
                var data = JSON.parse(data);
                if (data.returnCode == 1) {
//                    console.info(data);
                    if (data.content.grBgrq != null)
                    $("#xcJjbForm input[name='grBgrq']").val(data.content.grBgrq);
                    else
                        $("#xcJjbForm input[name='grBgrq']").val(0);
                    if (data.content.akBgrq != null)
                        $("#xcJjbForm input[name='akBgrq']").val(data.content.akBgrq);
                    else
                        $("#xcJjbForm input[name='akBgrq']").val(0);
                    if (data.content.ttm != null)
                        $("#xcJjbForm input[name='ttm']").val(data.content.ttm);
                    else
                        $("#xcJjbForm input[name='ttm']").val(0);
                } else {
                    $.showMessage({parentId: "showMessage", message: "数据加载异常！", type: "success"});
                }
            }
        });
    }
</script>